<?php
namespace app\admin\controller;
use app\admin\controller\BaseController;
use think\Db;
/**
 * 后台首页
 */
class IndexController extends BaseController {
	/**
	 * 首页
	 * @return mixed
	 */
	public function index() {
		$members=db("member")->field("count(user_id) counts,sum(money) balances")->find();
		$total_cz=db("paylog_copy")->where("order_type",3)->cache(30)->sum('balance');
		$total_fx=db("member_charge")->where("order_type",4)->cache(30)->sum('balance');
		$total_xf=db("paylog_copy")->where("order_type",1)->cache(30)->sum('balance');
		$today_member=db("member")->wheretime("add_time","today")->cache(30)->count("user_id");
		$week_member=db("member")->wheretime("add_time","week")->cache(30)->count("user_id");
		$month_member=db("member")->wheretime("add_time","month")->cache(30)->count("user_id");
		$orders=db('good_order')->cache(30)->count("id");
		$agents=db("agent")->cache(30)->count("id");
		$sj_goods=db('goods')->where("is_on_sale",1)->cache(30)->count("goods_id");
		$xj_goods=db('goods')->where("is_on_sale",2)->cache(30)->count("goods_id");
		$this->assign('members',$members);
		$this->assign('total_cz',$total_cz);
		$this->assign('total_fx',$total_fx);
		$this->assign('total_xf',$total_xf);
		$this->assign('today_member',$today_member);
		$this->assign('week_member',$week_member);
		$this->assign('month_member',$month_member);
		
		$this->assign('members',$members);
		$this->assign('orders',$orders);
		$this->assign('agents',$agents);
		$this->assign('sj_goods',$sj_goods);
		$this->assign('xj_goods',$xj_goods);
		return $this->fetch();
	}
	
	/**
	 * 清除缓存
	 */
	public function clear() {
		if (delete_dir_file(CACHE_PATH) || delete_dir_file(TEMP_PATH)) {
			$this->success('清除缓存成功');
		} else {
			$this->error('清除缓存失败');
		}
	}


}
